home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / Waste TCL r2 / CWASTEStyleTask.cp < prev    next >
Encoding:
Text File  |  1994-11-30  |  3.5 KB  |  156 lines  |  [TEXT/KAHL]

  1. /*
  2.  *
  3.  *    File:        CWASTEStyleTask.cp
  4.  *    Module:        CWASTEStyleTask method definitions
  5.  *    System:        Mark's Class Library
  6.  *    Evironment:    MacOS 7.0/THINK C 6.0/TCL 1.1.3
  7.  *    Author:        Mark Alldritt
  8.  *
  9.  *
  10.  *        Copyright © 1994    All Rights Reserved
  11.  *        Mark Alldritt
  12.  *        1571 Deep Cove Road
  13.  *        N. Vancouver, B.C. CANADA
  14.  *
  15.  *    
  16.  *    Description:
  17.  *
  18.  *  This class modifies the CTextStyleTask to allow it to work with CWASTEPane.
  19.  *
  20.  *
  21.  *    Acknowledgemets:
  22.  *
  23.  *    None.
  24.  *
  25.  *
  26.  *    Notes:
  27.  *
  28.  *    This source file depends on the "Scriptable TCL+MacTraps" pre-compiled header for all TCL
  29.  *    definitions.
  30.  *
  31.  *
  32.  *    Edit History:
  33.  *
  34.  *    V1-0.0    Mark Alldritt    10-May-1994
  35.  *    - Initial version of module.
  36.  *
  37.  */
  38.  
  39.  
  40. //#include "GlobalVars.h"
  41. #include "CWASTEText.h"
  42. #include "CWASTEStyleTask.h"
  43.  
  44.  
  45. CWASTEStyleTask::CWASTEStyleTask(CWASTEText *aTextPane, 
  46.                                  long aStyleCmd, short firstTaskIndex)
  47.     : CTextStyleTask( aTextPane, aStyleCmd, firstTaskIndex)
  48. {
  49.     long selStart, selEnd;
  50.     
  51.     oldStyles = NULL;
  52.     
  53.     itsTextPane->GetSelection( &selStart, &selEnd);
  54.     this->selStart = selStart;
  55.     this->selEnd = selEnd;
  56.     
  57. }    /* CWASTEStyleTask::IWASTEStyleTask */
  58.  
  59.  
  60. CWASTEStyleTask::~CWASTEStyleTask( void)
  61. {
  62.     TCLForgetHandle( oldStyles);
  63. }
  64.  
  65.  
  66. /******************************************************************************
  67.  Undo
  68.  
  69.      Undo the previously applied formatting. This method swaps the current and
  70.      previous styles, so it can perform both undo and redo.
  71. ******************************************************************************/
  72.  
  73. void CWASTEStyleTask::Undo( void)
  74. {
  75.     StScrpHandle    swapStyles, newStyles;
  76.     CWASTEText        *styleText = (CWASTEText*) itsTextPane;
  77.     
  78.     swapStyles = newStyles = NULL;
  79.  
  80.     TRY
  81.     {
  82.         if (styleAttribute < doAlign)
  83.         {
  84.             
  85.             itsTextPane->Prepare();    
  86.             itsTextPane->SetSelection( selStart, selEnd, TRUE);
  87.             
  88.             swapStyles = oldStyles;        /* save the current styling        */
  89.             oldStyles = NULL;
  90.             
  91.             SaveStyle();
  92.         
  93.             newStyles = oldStyles;
  94.             oldStyles = swapStyles;        /* restore the previous styling */
  95.             swapStyles = NULL;
  96.         
  97.             RestoreStyle();
  98.             
  99.             ForgetHandle( oldStyles);
  100.             
  101.             oldStyles = newStyles;        /* swap current and previous    */
  102.             
  103.             styleText->SetSpacingCmd( styleText->GetSpacingCmd());
  104.             styleText->SetWholeLines( styleText->GetWholeLines());
  105.             styleText->AdjustBounds();
  106.             
  107.             undone = !undone;
  108.  
  109.         }
  110.         else inherited::Undo();
  111.     }
  112.     CATCH
  113.     {
  114.         ForgetHandle( oldStyles);
  115.         ForgetHandle( newStyles);
  116.         ForgetHandle( swapStyles);
  117.     }
  118.     ENDTRY;
  119.  
  120. }    /* CWASTEStyleTask::Undo */
  121.  
  122. /******************************************************************************
  123.  SaveStyle
  124.  
  125.      Saves the current styling into oldStyles.
  126. ******************************************************************************/
  127.  
  128. void CWASTEStyleTask::SaveStyle( void)
  129. {
  130.     oldStyles = NULL;    /* GetStyleScrap may fail    */
  131.     
  132.     oldStyles = ((CWASTEText*)itsTextPane)->GetTheStyleScrap();
  133.  
  134. }    /* CWASTEStyleTask::SaveStyle */
  135.  
  136. /******************************************************************************
  137.  RestoreStyle
  138.  
  139.      Restores the saved styles from oldStyles back to the text.
  140. ******************************************************************************/
  141.  
  142. void CWASTEStyleTask::RestoreStyle( void)
  143. {
  144.     if (styleAttribute < doAlign)
  145.     {    
  146.         /* +++ work around problem with redoing cmdPlain on styled text? */
  147.         if ((styleCmd == cmdPlain) && (undone == TRUE))
  148.             itsTextPane->SetFontStyle( NOTHING);
  149.         else
  150.             ((CWASTEText *) itsTextPane)->SetTheStyleScrap(selStart, selEnd, oldStyles, TRUE);        
  151.     }
  152.     else
  153.         inherited::RestoreStyle();
  154.         
  155. }    /* CWASTEStyleTask::RestoreStyle */
  156.